package com.twu.biblioteca;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: mbokhari
 * Date: 11/07/2013
 * Time: 13:16
 * To change this template use File | Settings | File Templates.
 */
public class BookRetriever implements MenuInterface {
    private Library library = new Library();
    private Notifier notifier = new Notifier();

    public BookRetriever(Library library) {
        this.library = library;
    }

    public Book retrieveBooks(String title) {
        for (Book book : library.returnAllBooksInLibrary()) {
            if (book.getTitle().equals(title)) {
                return book;
            }
        }
        notifier.displayBookNotAvailableMessage();
        return null;
    }

    @Override
    public void runItems() throws IOException {

        notifier.printMessage("Please enter the title of the book you're trying to retrieve : ");

        InputReader inputReader = new InputReader();
        String titleOfBookYouWantToRetrieve = inputReader.readUserInputString();

        retrieveBooks(titleOfBookYouWantToRetrieve);
    }
}
